/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components;

import hpvas.HPVAS;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 *
 * @author Juan
 */
public class PSearchResults extends javax.swing.JPanel {

    /**
     * Creates new form PSearchResults
     */
    public PSearchResults() {
        initComponents();
    }
    
    public PSearchResults(String[] searchWords, String searchingBy, List results) {
        initComponents();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < searchWords.length; i++) {
            sb.append(searchWords[i]).append(" ");
        }
        LSearchWords.setText(sb.toString());
        LSearchingBy.setText(searchingBy);
        if (!results.isEmpty()) {
            DefaultListModel model = new DefaultListModel();
            for (Object object : results) {
                model.addElement(object);
            }
            LResults.setModel(model);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        LSearchWords = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        LSearchingBy = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        LResults = new javax.swing.JList();
        BClose = new javax.swing.JButton();

        jLabel1.setText("Search words:");

        LSearchWords.setText("jLabel2");

        jLabel2.setText("Searching by:");

        LSearchingBy.setText("jLabel3");

        jLabel3.setText("Results (Double click to see details):");

        LResults.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "<No matches were found>" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        LResults.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        LResults.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                LResultsMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(LResults);

        BClose.setText("Close");
        BClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCloseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LSearchWords))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LSearchingBy))
                            .addComponent(jLabel3)
                            .addComponent(BClose))
                        .addGap(0, 208, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(LSearchWords))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(LSearchingBy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(BClose)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void BCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCloseActionPerformed
        HPVAS.closeCurrentTab();
    }//GEN-LAST:event_BCloseActionPerformed

    private void LResultsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LResultsMouseClicked
        if (evt.getClickCount() == 2) {
            HPVAS.displayEntity(LResults.getSelectedValue());
        }
    }//GEN-LAST:event_LResultsMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BClose;
    private javax.swing.JList LResults;
    private javax.swing.JLabel LSearchWords;
    private javax.swing.JLabel LSearchingBy;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
